define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            Table.api.init({
                extend: {
                    index_url: 'faq/index',
                    add_url: 'faq/add',
                    edit_url: 'faq/edit',
                    del_url: 'faq/del',
                    detail_url: 'faq/detail',
                    table: 'faq',
                }
            });

            var table = $("#table");

            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('ID') },
                        { field: 'question', title: __('Question') },
                        { field: 'answer', title: __('Answer'), visible: false },
                        { field: 'weigh', title: __('Weigh'), sortable: true },
                        { field: 'status', title: __('Status'), searchList: { "1": __('Normal'), "0": __('Hidden') }, formatter: Table.api.formatter.status },
                        { field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, sortable: true },
                        { field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, sortable: true },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
}); 